import java.util.LinkedList;

/**
 * This class builds path in a graph
 * 
 * @author Hyangjin Lee
 *
 */
public class Path implements Comparable<Path> {

	private int weight;
	
	private Vertex start, end;

	private LinkedList<Edge> edges;

	/**
	 * Create an initial path where start and end are the given vertex
	 * 
	 * @param vertex
	 *            a vertex
	 */
	public Path(Vertex vertex) {
		start = end = vertex;
	}

	/**
	 * Assume that one of the vertices (either u or v) in the edge is the end vertex of old. Copies
	 * the old path and adds the edge e. (Make sure to update the end vertex, and weight correctly)
	 * 
	 * @param old
	 *            a path that ends in u or v
	 * @param e
	 *            an edge between vertices u and v
	 */
	public Path(Path old, Edge e) {
		Vertex u = e.getU();
		Vertex v = e.getV();
		
		edges.add(e);
		weight += e.getWeight();
		
		if(old.getEnd()==u)
			this.end = v;
		else
			this.end = u;
	}

	@Override
	public int compareTo(Path that) {
		if(weight<that.getWeight())
			return -1;
		else if(weight==that.getWeight())
			return 0;
		else
			return 1;		
	}
	
	@Override
	public String toString() {
		// TODO Extra Credit
		return "Path";
	}

	/**
	 * Returns weight
	 * @return The total weight of the path
	 */
	public int getWeight() {
		return weight;
	}
	
	/**
	 * Returns the starting vertex of the path
	 * @return The starting vertex of the path
	 */
	public Vertex getStart() {
		return start;
	}
	
	/**
	 * Returns the ending vertex of the path
	 * @return The last vertex in the path
	 */
	public Vertex getEnd() {
		return end;
	}
	
	/**
	 * Returns the LinkedList of edges
	 * @return The LinkedList of edges in the path
	 */
	public LinkedList<Edge> getEdges() {
		return edges;
	}
}
